import request from '@/utils/request'

// 查询合同主列表
export function listContract(query) {
  return request({
    url: '/manager/contract/list',
    method: 'get',
    params: query
  })
}

// 查询合同主详细
export function getContract(id) {
  return request({
    url: '/manager/contract/' + id,
    method: 'get'
  })
}
// 查询合同模版列表
export function getTemplateList() {
  return request({
    url: '/manager/contract/getTemplateList?current=1&size=-1',
    method: 'get'
  })
}
// 根据模版记录id查询合同表单字段
export function getTemplateFieldsById(id) {
  return request({
    url: '/manager/contract/getTemplateFieldsById?id='+id,
    method: 'get'
  })
}
// 根据手机号码查询客户
export function getCustomerByPhone(phone,type) {
  return request({
    url: '/manager/contract/getCustomerByPhone?phone='+phone+"&type="+type,
    method: 'get'
  })
}

// 新增合同主
export function createContract(data) {
  return request({
    url: '/manager/contract/createContract',
    method: 'json',
    data: data
  })
}
// 添加合同客户
export function addContractCustomer(data) {
  return request({
    url: '/manager/contract/addContractCustomer',
    method: 'json',
    data: data
  })
}

// 添加合同信息
export function saveContractDetail(data) {
  return request({
    url: '/manager/contract/saveContractDetail',
    method: 'post',
    data: data
  })
}

//锁定生成合同
export function lockAndProduceContract(id,flag) {//flag是否检查签署者（0检查 1忽略）
  return request({
    url: '/manager/contract/lockAndProduceContract?id='+id+'&flag='+flag,
    method: 'get'
  })
}

// 修改合同主
export function updateContract(data) {
  return request({
    url: '/manager/contract',
    method: 'put',
    data: data
  })
}

// 删除合同主
export function delContract(id) {
  return request({
    url: '/manager/contract/delete/' + id,
    method: 'delete'
  })
}

// 导出合同主
export function exportContract(query) {
  return request({
    url: '/manager/contract/export',
    method: 'get',
    params: query
  })
}

/**
 * 退款
 * @param data
 */
export function refund (data) {
  return request({
    url: '/manager/contract/contractRefund/refund',
    method: 'post',
    params: data
  })
}

/**
 * 作废合同
 * @param data
 */
export function cancelContract (data) {
  return request({
    url: '/manager/contract/cancelContract',
    method: 'get',
    params: data
  })
}
